class Util {
  static List<T>? getTypedList<T>(data, T? Function(Map? map) creator) {
    List? list = data as List?;
    return toList(list, creator);
  }

  static List<T>? toList<T>(List? mapList, T? Function(Map? map) creator) {
    if (mapList == null) {
      return null;
    }
    List<T> ret = [];
    for (var m in mapList) {
      if (m == null) continue;
      var t = creator(m);
      if (t != null) {
        ret.add(t);
      }
    }
    return ret;
  }

  static String formatTime(DateTime now) {
    String formattedTime = '${now.year.toString().padLeft(4, '0')}-'
        '${now.month.toString().padLeft(2, '0')}-'
        '${now.day.toString().padLeft(2, '0')} '
        '${now.hour.toString().padLeft(2, '0')}:'
        '${now.minute.toString().padLeft(2, '0')}';
    return formattedTime.split(" ")[0];
  }
}
